﻿using System.Collections.Generic;
using System.Linq;
using EnvDTE;
using EnvDTE80;
using LazyPlugins.Common;

namespace LazyPlugins.AttachManager
{
    public class DebuggerInfo : IDebuggerInfo
    {
        private readonly DTE2 _dte;

        public DebuggerInfo(DTE2 dte)
        {
            _dte = dte;
        }

        public Engines Engines
        { 
            get
            {
                var trans = Transport;
                return trans.Engines;
            } 
        }

        public IEnumerable<Process> DebuggedProcesses
        {
            get { return Debugger.DebuggedProcesses == null ? new Process[0] : Debugger.DebuggedProcesses.Cast<Process>(); }
        }

        private Transport Transport
        {
            get { return Debugger.Transports.Item("Default"); }
        }

        private Debugger2 Debugger
        {
            get
            {
                return ((Debugger2) _dte.Debugger);
            }
            
        }

        public Process2 GetProcess(string processName)
        {
            return Debugger.GetProcesses(Transport, "").Item(processName) as Process2;
        }
    }
}
